<template>
    <div id="headBox">
        <div class="everyBlockPadding headMain">
            <div class="back translateBlock" v-show="isShowBack" @click="goback()">X</div>
            <div class="translateBlock headTitle" :style="{width:isShowBack ? '8rem' : '100%'}">{{title}}</div>
        </div>
    </div>
</template>

<script>
    export default {
        name: '',
        props: {
            title: {
                type: String,
                default: '',
            },
            isShowBack: {
                type: Boolean,
                default: true,
            }
        },

        data() {
            return {
                historyPathList: this.$store.state.user.historyPathList,
            }
        },

        watch: {
            currentName(val) {
                console.log(val)
            },
        },

        computed: {
            currentName() {
                if (this.$route.name === 'home' || this.$route.name === 'historyHot' || this.$route.name ===
                    'yuyueProduct' || this.$route.name === 'personCenter' || this.$route.name === 'goodsSearchList') {
                    this.historyPathList = [this.$route];
                } else {
                    let _check = false;
                    for (let i in this.historyPathList) {
                        let item = this.historyPathList[i];
                        if (item.name === this.$route.name) {
                            this.historyPathList[i] = this.$route;
                            _check = true;
                            break;
                        }
                    }

                    if (!_check) {
                        this.historyPathList.push(this.$route);
                    }
                }

                this.$store.dispatch('changeHistoryPathList', this.historyPathList)
                return this.$route.name;
            },
        },

        methods: {
            goback() {

                let length = this.historyPathList.length;
                let param = [];
                for (let i = 0; i < length - 1; i++) {
                    param.push(this.historyPathList[i])
                }
                let _length = param.length;
                this.$tools.goPage(param[_length - 1].fullPath)
                this.$store.dispatch('changeHistoryPathList', param)
            },
        },
    }
</script>

<style lang="less" rel="stylesheet/less" type="text/css">

    .headMain {
        width: 100%;
        box-sizing: border-box;
        height: 1.2rem;
        line-height: 1.2rem;
        background: #ededed;
        position: fixed;
        z-index: 99;
        top: 0;
        font-size: 0.39rem;
        color: #4E4E4E;
        /*display: flex;*/
        /*align-items: center;*/
        /*justify-content: space-between;*/
        font-weight: bold;
    }
    .headTitle {
        text-align: center;
    }
    .back {
        width: 1rem;
        font-size: 0.34rem;
        color: #000;
    }
</style>
